package com.team.controller;

import com.team.dto.DocumentDto;
import com.team.service.DocumentService;
import com.team.vo.DocumentReviewVo;
import com.team.vo.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping
@Slf4j
public class DocumentController {
    @Autowired
    private DocumentService documentService;

    /**
     * 获得所有审核
     * @return
     */
    @GetMapping("/getAdmin_document_approvals")
    public Result<List<DocumentReviewVo>> getAllApprovals(){
        return Result.success(documentService.getAllApprovals());
    }

    /**
     * 进行审核（设置状态）
     * @param studentId
     * @param status
     * @param did
     * @return
     */
    @PostMapping("/updateAdmin_document_approvals")
    public Result updateDocumentStatus(@RequestParam("student_id") int studentId,int did,int status){
        documentService.updateDocumentStatus(studentId,status,did);
        return Result.success();
    }

    /**
     * 查找团队对应的所有审核内容  注意：前端的student_id实际上是此时的队长id
     * @param applicantId
     * @return
     */
    @GetMapping("/getDocument_approvals")
    public Result<List<DocumentReviewVo>> getMyApprovals(@RequestParam("student_id") int applicantId){
        return Result.success(documentService.getMyApprovals(applicantId));
    }

    /**
     * 提交审核
     * @param documentDto
     * @return
     */
    @PostMapping("/addDocument_approvals")
    public Result addDocumentApproval(@RequestBody DocumentDto documentDto){
        log.info("添加申请{}",documentDto);
        documentService.addDocumentApproval(documentDto);
        return Result.success();
    }

}
